var a,
  t =
    (a = require("../../@babel/runtime/regenerator")) && a.__esModule
      ? a
      : { default: a },
  e = require("../../@babel/runtime/helpers/asyncToGenerator");
Component({
  properties: {
    src: String,
    title: { type: String, default: "展品介绍" },
    time: {
      type: Number,
      default: 0,
      observer: function (a) {
        this.setData({ duration: this.format(a), totalTime: a });
      },
    },
    autoplay: { type: Boolean, default: !1 },
    info: Object,
  },
  data: {
    backgroundColor: "#DCDCDC",
    initializeColor: "#DCDCDC",
    audio: { src: "", paused: !1, currentTime: 0, duration: 0 },
    current: "",
    duration: "",
    paused: !0,
    seek: !1,
    progress: 0,
    totalTime: 0,
  },
  ready: function () {
    var a = this;
    this.setData(
      { audio: wx.getBackgroundAudioManager(), current: this.format(0) },
      function () {
        console.log(wx.getBackgroundAudioManager().paused, "paused");
        var t = a.data.audio;
        console.log(t, "audio"),
          a.setData({ paused: t.paused }),
          t.src !== a.data.src
            ? a.setData({ paused: !0 })
            : t.src !== a.data.src || t.paused || a.setData({ paused: !1 }),
          t.onTimeUpdate(function () {
            console.log("音频进度更新事件", a.data, t),
              a.data.seek ||
                t.src !== a.data.src ||
                a.setData({
                  current: a.format(t.currentTime),
                  progress: t.currentTime,
                }),
              a.data.duration || a.setData({ duration: t.duration });
          }),
          t.onPlay(function () {
            console.log("音频播放事件"), a.setData({ paused: !1 });
          }),
          t.onPause(function () {
            console.log("音频暂停事件"), a.setData({ paused: !0 });
          }),
          t.onEnded(function () {
            console.log("音频结束事件"),
              a.setData({ paused: !0, current: a.format(0), progress: 0 });
          }),
          t.onSeeked(function () {
            console.log("seeked"), a.setData({ seek: !1 });
          });
      },
    );
  },
  methods: {
    format: function (a) {
      return ""
        .concat(
          "0".repeat(2 - String(Math.floor(a / 60)).length) +
            Math.floor(a / 60),
          ":",
        )
        .concat("0".repeat(2 - String(Math.floor(a % 60)).length))
        .concat(Math.floor(a % 60));
    },
    handleAudioManageFunc: function () {
      var a = this;
      return e(
        t.default.mark(function e() {
          return t.default.wrap(function (t) {
            for (;;)
              switch ((t.prev = t.next)) {
                case 0:
                  console.log(a.data.paused, "paused"),
                    a.data.paused || void 0 === a.data.paused
                      ? a.play()
                      : a.pause();
                case 2:
                case "end":
                  return t.stop();
              }
          }, e);
        }),
      )();
    },
    play: function () {
      var a = this.data.audio;
      a.src !== this.data.src &&
        this.setData({
          "audio.src": this.data.src,
          "audio.title": this.data.info.name,
        }),
        a.play();
    },
    pause: function () {
      this.data.audio.pause();
    },
    handleSliderChange: function (a) {
      var t = a.detail.value;
      this.setData({ progress: t, current: this.format(t) }),
        this.data.audio.seek(t);
    },
  },
});
